﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CodeGenLib;

namespace TestCodeGenLib
{
    class TestParamFormatter
    {
        public TestParamFormatter()
        {
            this.paramFormatter = new ParamCreater();
        }

        public void Test()
        {
            GenParam param = new GenParam();
            param.AddBases("Base1");
            param.AddBases("sf::Base2");
            param.Class = "Test";
            param.Namespace = "test";

            this.paramFormatter.Format(param);

            GenParam desire = new GenParam();
            desire.AddBases("Base1");
            desire.AddBases("sf::Base2");
            desire.AddInclude("\"Base1.h\"");
            desire.AddInclude("<sf/Base2.h>");

            if (param.Bases.Count != desire.Bases.Count ||
                param.Includes.Count != desire.Includes.Count)
            {
                throw new Exception("TestParamFormatter - failed");
            }

            for (int i = 0; i < param.Bases.Count; ++i)
            {
                if (param.Bases[i] != desire.Bases[i])
                {
                    throw new Exception("TestParamFormatter - failed");
                }
            }

            for (int i = 0; i < param.Includes.Count; ++i)
            {
                if (param.Includes[i] != desire.Includes[i])
                {
                    throw new Exception("TestParamFormatter - failed");
                }
            }

            this.TestHeaderGuard("test", "TestClass", "test_Test_Class_h");
            this.TestHeaderGuard("ns", "Animation3d", "ns_Animation3d_h");
            this.TestHeaderGuard("test", "MQMap", "test_MQ_Map_h");

            Console.WriteLine("TestParamFormatter: suceed");
        }

        private void TestHeaderGuard(String ns, String className, String desireHeaderGuard)
        {
            GenParam param = new GenParam();
            param.Namespace = ns;
            param.Class = className;
            this.paramFormatter.Format(param);
            if (param.HeaderGuard != desireHeaderGuard)
            {
                String msg = "TestParamFormatter - failed";
                msg += "\nHeaderGuard: " + param.HeaderGuard;
                msg += "\ndesire: " + desireHeaderGuard;
                throw new Exception(msg);
            }
        }

        private ParamCreater paramFormatter;
    }
}
